/*
 * helpers.c
 *
 * Created: 9/14/2012 10:30:02 AM
 *		Author: zimmermane@msoe.edu <Evan Zimmerman>
 *				duerk@msoe.edu <Kevin Duer>
 *				
 *	Purpose: this is used to create delays
 */ 


#include "helpers.h"
#include <stdint.h>

/*
 * delay_ms
 * Purpose: will delay for the entered value of millisecond
 * Parameters: ms: the milliseconds to delay
 * Returns: None
 */
void delay_ms(uint16_t ms)
{
	volatile uint16_t i;

	for(i=ms;i>0;i--)
	{
		delay_us(1000);
		delay_us(1000); // added for 16MHz clock
	}
}

/*
 * delay_us
 * Purpose: will delay for the entered value of microseconds
 * Parameters: us: the microseconds to delay
 * Returns: None
 */
void delay_us(uint16_t us)
{
	// The following gives the correct delay if FCPU=8MHZ
	asm volatile (
	"lsl r24" "\n\t"
	"rol r25" "\n\t"
	"1: sbiw r24,1" "\n\t"
	"brne 1b"
	);
}